import Taro, { Component } from '@tarojs/taro'
import { View, Text,Image } from '@tarojs/components'
import {AtIcon } from 'taro-ui'
import './aolideOperation.scss'
import eyes from '../../img/eyes.png'
import app from '../../main';

export default class aolideOperation extends Component {

    config = {
      navigationBarTitleText: ''
    } 
    constructor(){
        super(...arguments)
        this.state={
            taocaoInfo: []
        }
    }

    //跳转到手术详情页面
    gotoAolideOpmeal(id){
        app.navigateTo('../aolideOpmeal/aolideOpmeal?id='+id+'&hospital_id='+this.$router.params.id+'&title='+this.$router.params.title)
    }

    offset = 0;
    length = 8;
    total = 0;
    isFinlsh = false;
    
    //调用接口获取数据
    
    // //将接口返回数据与原来数据拼接
    // let me  = this
    // let dcoArray =  docArray.concat(res.data.result)
    // me.total  = res.res.data.total
    // me.setState(){
    // }
    
    //上拉加载
    onReachBottom(){
        if ((this.offset+this.length) < this.total) {
            app.toast('正在加载----')
            this.offset = this.offset + length;
            this.isFinlsh = false;
            //调用接口
        }else{
            app.toast('没有更多数据了咯')
            this.isFinlsh = true;
        }
    }

    getData(){
        let me = this
        let arr = []
        let data = {offset:this.offset,length:this.length,hospital_id:this.$router.params.id}
        app.get('web/hospital/hospitalServer',data,function(res){
            let dcoArray =  arr.concat(res.data.result.data)
            me.total = res.data.result.total
            me.setState({
                taocaoInfo:dcoArray
            },()=>{
                console.log(me.state.taocaoInfo)
            })
        })
    }
    componentDidMount(){
        this.getData();
        Taro.setNavigationBarTitle({
            title:this.$router.params.title
        })
    }

    render(){
        return(
            <View>
                {this.state.taocaoInfo.map((item) => {
                    return  <View className='serviceBox' onClick={this.gotoAolideOpmeal.bind(this,item.id)}>
                       <View><Image src={item.shrink_image} className='serviceImg'/></View>
                       <View className='serviceCon'>
                          <View className='serviceName'>{item.title}</View>
                          <View className='servicePay'>
                              <View className='nowMoney'>
                                  现价: <Text className='now'>  {item.current_price}</Text>
                              </View>
                              <View className='oldMoney'>
                                  原价: <Text className='old'>  {item.original_price}</Text>
                              </View>
                          </View>
                          <View className='status'>
                               <View><Image src={eyes} className='eyes'/></View>
                               <View className='persons'><Text>{item.make_num}</Text>人预约成功</View>
                          </View>
                       </View>
                   </View>
                })}
            </View>
        )
    }
}